package com.qf.service.impl;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.cache.annotation.CacheKey;
import com.netflix.hystrix.contrib.javanica.cache.annotation.CacheRemove;
import com.netflix.hystrix.contrib.javanica.cache.annotation.CacheResult;
import com.qf.feign.GoodsFeign;
import com.qf.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TestServiceImpl implements TestService {
    @Autowired
    GoodsFeign goodsFeign;

    @Override
    //返回值就是缓存的值
    @CacheResult
    //这个findByCondition就是缓存的key
    @HystrixCommand(commandKey = "testCache")
    //参数也作为缓存key的一部分
    public String test(Integer id) {
        return goodsFeign.query(id);
    }

    @Override
    @HystrixCommand
    @CacheRemove(commandKey = "testCache")
    public String clearCache(@CacheKey Integer id) {
        return null;
    }
}
